<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>jsApiPay</title>
</head>
<body>
<script>

    function doPay(){
        var ret = '${retStr}';
        var callPayParam = JSON.parse(ret);
        if(callPayParam.code == undefined){
            onBridgeReady(callPayParam)//唤起支付
        }else{
            alert(callPayParam.code + "," + callPayParam.message);
        }
    }
    function onBridgeReady(callPayParam) {
        WeixinJSBridge.invoke('getBrandWCPayRequest', callPayParam,
            function(res) {
                if (res.err_msg == "get_brand_wcpay_request:ok") {
                    // 使用以上方式判断前端返回,微信团队郑重提示：
                    //res.err_msg将在用户支付成功后返回ok，但并不保证它绝对可靠。
                    window.history.back(-1);
                }
            });
    }
    if (typeof WeixinJSBridge == "undefined") {
        if (document.addEventListener) {
            document.addEventListener('WeixinJSBridgeReady', doPay, false);
        } else if (document.attachEvent) {
            document.attachEvent('WeixinJSBridgeReady', doPay);
            document.attachEvent('onWeixinJSBridgeReady', doPay);
        }
    } else {
        doPay();
    }
</script>
</body>
</html>